package com.lcxw.hxzbapi.service.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lcxw.hxzbapi.dao.mapper.AvatarMapper;
import com.lcxw.hxzbapi.entity.pojo.Avatar;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.service.AvatarService;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class AvatarServiceImpl extends ServiceImpl<AvatarMapper, Avatar> implements AvatarService {

    @Override
    public Response getAll(String name, Integer status, int pageNum, int pageSize) {
        IPage<Avatar> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Avatar> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(name != null, Avatar::getName, name);
        queryWrapper.lambda().eq(status != null, Avatar::getStatus, status);
        page = page(page, queryWrapper);
        long total = page.getTotal();
        List<Avatar> records = page.getRecords();
        JSONObject data = new JSONObject();
        data.put("total", total);
        data.put("list", records);
        return Response.ok(data);
    }
}
